package com.taotao.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.common.pojo.EUDataGridResult;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.pojo.TbItem;
import com.taotao.service.ItemService;
import com.taotao.service.RedisService;

@Controller
public class ItemController {
	@Autowired
	private ItemService itemService;
	@Autowired
	private RedisService redisService;

	
	@RequestMapping(value="/item/{id}",method=RequestMethod.GET)
	@ResponseBody
	public TbItem selectItemById(@PathVariable long id) {
		TbItem item = itemService.getItemById(id);
		return item;
		
	}
	
	@RequestMapping(value="/item/list", method=RequestMethod.GET)
	@ResponseBody
	public EUDataGridResult getItemList(int page, int rows) {
		return itemService.getItemList(page, rows);
	}
	
	@RequestMapping(value="/item/save", method=RequestMethod.POST)
	@ResponseBody
	public TaotaoResult saveItem(TbItem item, String desc, String itemParams) throws Exception {
		
		redisService.synItem();
		return itemService.createItem(item, desc, itemParams);
		 
	}
}
